home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / backupod / unmountod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  1.6 KB  |  56 lines

  1. /* unmountbackupod - unmount and eject an od
  2.  */
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7. #define UNIT    "0a"                    /* Default unit number */
  8. #define DEVICE    "od"                    /* Default (only available) device name */
  9. #define DEVDIR    "/dev"                    /* Default (only available) device directory */
  10. #define UMOUNT    "/usr/etc/umount"        /* Command for unmounting filesystem */
  11. #define EJECT    "/usr/etc/disk -e"        /* Command for ejecting disk */
  12.  
  13. #define MAX(x, y)    \
  14.     (x > y ? x : y)
  15.  
  16. main(int argc, char *argv[])
  17. {
  18.     char    *unit,
  19.             *cmdbuf,
  20.             *PgmName;
  21.  
  22.     PgmName = basename(argv[0]);        /* So messages look nice */
  23.  
  24.     if (argc > 2) {            /* Arguments provided? */
  25.         (void)fprintf(stderr, "%s: wrong number of arguments\n", PgmName);
  26.         (void)fprintf(stderr, "Usage: %s [UNIT]\n", PgmName);
  27.         (void)fprintf(stderr,
  28.     "\tUNIT is the OD unit number (e.g., 0a) to be unmounted and ejected\n", DEVDIR);
  29.         exit(1);
  30.     } else if (argc == 2) {        /* One argument provided */
  31.         unit = argv[1];
  32.     } else {                    /* No arguments provided; use defaults */
  33.         unit = UNIT;
  34.     }
  35.  
  36.     cmdbuf = (char *)malloc(MAX(strlen(UMOUNT), strlen(EJECT) +1) + strlen(DEVDIR)   +
  37.                             strlen(DEVICE) + strlen(unit) + 3);
  38.             /* +3 in above for ' ' and '/' before unit name, and for '\0' to terminate
  39.              * and the +1 is for the 'r' in /dev/rod0a
  40.              */
  41.     (void)sprintf(cmdbuf, "%s %s/%s%s", UMOUNT, DEVDIR, DEVICE, unit);
  42.     if (0 != system(cmdbuf)) {
  43.         (void)fprintf(stderr, "%s: problems unmounting %s.\n", PgmName, unit);
  44.         exit(1);
  45.     }
  46.  
  47.     (void)sprintf(cmdbuf, "%s %s/r%s%s", EJECT, DEVDIR, DEVICE, unit);
  48.     if (0 != system(cmdbuf)) {
  49.         (void)fprintf(stderr, "%s: problems ejecting %s.\n", PgmName, unit);
  50.         exit(1);
  51.     }
  52.  
  53.     exit(0);
  54. }
  55.  
  56.